# -----------------------------------------------------------------------------
# Copyright (c) 2025, Southeast University (China)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#  - Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  - Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  - Neither the name of the copyright holders nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Jiajie Xu, Yanfang Zhang, Jiaqi Gao, Leyun Tian
# -----------------------------------------------------------------------------


set starttime [clock seconds]
echo "INFORM: Start job at: " [clock format $starttime -gmt false]
set is_si_enabled false

set top_design sasc_top

set link_library "* /home/techlibs/TSMC/12nm/standcell/9t/tcbn12ffcllbwp16p90_100a/0M18012_20230605/TSMCHOME/digital/Front_End/timing_power_noise/CCS/tcbn12ffcllbwp16p90_100a/tcbn12ffcllbwp16p90ssgnp0p63v125c_ccs.db \
    /home/techlibs/TSMC/12nm/standcell/9t/tcbn12ffcllbwp16p90lvt_100a/0M18012_20230605/TSMCHOME/digital/Front_End/timing_power_noise/CCS/tcbn12ffcllbwp16p90lvt_100a/tcbn12ffcllbwp16p90lvtssgnp0p63v125c_ccs.db \
    /home/techlibs/TSMC/12nm/standcell/9t/tcbn12ffcllbwp16p90ulvt_100a/0M18012_20230605/TSMCHOME/digital/Front_End/timing_power_noise/CCS/tcbn12ffcllbwp16p90ulvt_100a/tcbn12ffcllbwp16p90ulvtssgnp0p63v125c_ccs.db"


#set netlist "/home/jiajiexu/mylib/ICC2_Lab/SMIC14/ICC2_Labs.ndm/sasc_top/attach/design.signoff.eco.data/design.full.v"
set netlist "../innovus_data/${top_design}/${top_design}_postRoute_fill_std.v"
set sdc "../innovus_data/${top_design}/${top_design}_postRoute_fill_std.enc.dat/mmmc/modes/func/func.sdc"
set spef "../innovus_data/${top_design}/${top_design}_postRoute_fill_std_rcworst_CCworst.spef"

source -e -v ../pt_scripts/varaible.tcl

set NET_FILE $netlist
set SDC_FILE $sdc
set SPEF_FILE $spef


###################################################################
read_verilog  $NET_FILE
current_design $top_design
link

read_parasitics -keep_capacitive_coupling  -format SPEF  $SPEF_FILE


source -e -v $SDC_FILE

set_propagated_clock [all_clocks]

set timing_remove_clock_reconvergence_pessimism false

#set_clock_uncertainty 0.1 [all_clocks] -setup
#set_clock_uncertainty 0.2  [all_clocks] -hold

set timing_disable_clock_gating_checks true
set timing_report_unconstrained_paths true

# use the basic NLDM driver and reciver model, default is advanced, which is CCS model
set rc_driver_model_mode basic
set rc_receiver_model_mode basic

update_timing -full
update_power

set dir_path "../pt_data/${top_design}"
if {![file exists $dir_path]} {
    file mkdir $dir_path
}

report_timing  -nets -input_pins -transition_time -capacitance -significant_digit 9 -max_path 3
report_cell -connections -nosplit > ../pt_data/${top_design}/${top_design}_cell.rpt
report_net -connections -verbose > ../pt_data/${top_design}/${top_design}_net.rpt

report_timing -nosplit -nets -input_pins -transition_time -significant_digit 6 -delay_type min_max  -nworst 1000 -slack_lesser_than 10000 > ../pt_data/${top_design}/${top_design}_timing.rpt


source ../pt_scripts/pt_util2.tcl
report_scenario_data_for_icexplorer -scenario_name func_slow -dir ../pt_data/${top_design}

source ../pt_scripts/get_pin_arrival.tcl > ../pt_data/${top_design}/${top_design}_pin_arrival.rpt
source ../pt_scripts/get_pin_transition.tcl > ../pt_data/${top_design}/${top_design}_pin_transition.rpt
source ../pt_scripts/get_pin_caps.tcl > ../pt_data/${top_design}/${top_design}_pin_caps.rpt
source ../pt_scripts/get_pin_type.tcl > ../pt_data/${top_design}/${top_design}_pin_type.rpt
source ../pt_scripts/get_cell_leakage.tcl > ../pt_data/${top_design}/${top_design}_leakage.rpt
source ../pt_scripts/get_port_arrival.tcl > ../pt_data/${top_design}/${top_design}_port_arrival.rpt
source ../pt_scripts/get_timing_arcs.tcl > ../pt_data/${top_design}/${top_design}_timing_arcs.rpt

set endtime   [clock seconds]
echo "INFORM: End job at: " [clock format $endtime -gmt false]
set pwd [pwd]
set runtime "[format %02d [expr ($endtime - $starttime)/3600]]:[format %02d [expr (($endtime - $starttime)%3600)/60]]:[format %02d [expr ((($endtime - $starttime))%3600)%60]]"
echo [format "%-15s %-2s %-70s" " | runtime" "|" "$runtime"]
report_global_timing > ../pt_data/${top_design}/${top_design}_glb_timing.rpt

exit
